Load some packages that we’ll need to use to do these calculations:

library(tidyverse)
library(gifski)
library(ggraph)
library(here)
library(igraph)
source(here("modelFunction_rewiring.R"))

1. Run the model once

# Define parameters
N = 50
edge.prob <- 0.04
n.removed = 10
burn.in = 20
recovery = 5
add00 = c(0.5, 10)
lose01 = 0.1
add10 = 0.05
lose11 = c(0.5, 0.5)
coefAdd = 0.5
coefLose = -0.5
modelGraphs <- runModel(N = N, # Nodes in the network
                        edge.prob = edge.prob,
                        n.removed = n.removed,
                        burn.in = burn.in,
                        recovery = recovery,
                        add00 = add00, 
                        lose01 = lose01, 
                        add10 = add10,
                        lose11 = lose11,
                        coefAdd = coefAdd,
                        coefLose = coefLose)$graphs

2. For a single model run, examine network-level measures over time

## Warning: Removed 1 row(s) containing missing values (geom_path).

4. Relationship between removed nodes and network-level measures

A few sanity checks:

What about the ratio between the first and second changes? Aka: what percentage of the loss/gain is recovered by the rewiring?

## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced
## Warning: Removed 895 rows containing non-finite values (stat_smooth).
## Warning: Removed 881 rows containing missing values (geom_point).

## Warning in log(ratio): NaNs produced
## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced
## Warning: Removed 895 rows containing non-finite values (stat_smooth).
## Warning: Removed 881 rows containing missing values (geom_point).

## Warning: Removed 14 rows containing non-finite values (stat_smooth).

## Warning: Removed 14 rows containing non-finite values (stat_smooth).